package com.wingsboat.sort;

/**
 * @author wangzhong
 * @description: 冒泡排序
 * @date 2024/7/21 10:26
 */
public class BubbleSort {
    private BubbleSort(){}

    public static void main(String[] args) {
        int[] arr = {5,2,7,0,8,6,3,1,2};
        BubbleSort.sort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void sort(int[] arr){
        for(int i=0;i<arr.length-1;i++){
            for(int j = 0;j<arr.length-i-1;j++){
                if(arr[j]>arr[j+1]) swap(j,j+1,arr);
            }
        }
    }
    public static void swap(int a,int b,int[] arr){
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;

    }
}
